<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <button class="layui-btn" id="isCheckFun" style="border-radius: 4px;margin-bottom: 10px">确认选择</button>
            <table id="productStorageWorkOutFormTableTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        const nowData={...parentData}
        // let cacheList = nowData.cacheList
        table.render({
            elem: '#productStorageWorkOutFormTableTable',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'}
                , {field: 'productDetailId', title: '物料ID', hide: true}
                , {field: 'skuCode', title: '物料编码', align: 'center'}
                , {field: 'skuName', title: '物料名称', align: 'center'}
                , {field: 'skuSpec', title: '物料规格', align: 'center'}
                , {field: 'materialNatureName', title: '物料类别性质', align: 'center'}
                , {field: 'productTypeName', title: '物料类别', align: 'center'}
                , {field: 'receiptNum', title: '领取数量', align: 'center'}
                , {field: 'unitName', title: '计量单位', align: 'center'}
                , {field: 'baseUnitName', title: '基础单位', align: 'center'}
                , {field: 'leaveQuantity', title: '本单剩余出库量', align: 'center'}
                , {field: 'createTime', title: '创建时间', align: 'center', width: 170}
            ]],
            done: function () {
                // if (nowData.cacheList.length > 0) {
                //   table.cache['productStorageWorkOutFormTableTable'].forEach((item, index) => {
                //     const isSelected = parentData.cacheList.some(checkItem => checkItem.productDetailId === item.id);
                //     if (isSelected) {
                //       item["LAY_CHECKED"] = true
                //       $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').prop('checked', true);
                //       $('div.layui-table-body input[name="layTableCheckbox"]:eq(' + (index) + ')').next().addClass('layui-form-checked');
                //     }
                //   });
                // }
                // form.render('checkbox');
            }
        });
        if(nowData.dataList){
            console.log(nowData);
            let list = nowData.dataList.filter((v) => {
                return !nowData.cacheList.some((item) => item.id === v.id);
            });
            table.reload('productStorageWorkOutFormTableTable', {
                data: list
            })      
        }
        $('#isCheckFun').click(() => {
            var checkStatus = table.checkStatus('productStorageWorkOutFormTableTable'); // 'demo'是表格的ID
            var data = checkStatus.data;  // 选中的数据
            if (typeof parent.layui !== 'undefined') {
                childData.list = data.map(v => {
                    // v.orderDetailId = v.id;
                    // delete v.id
                    return v
                })
                layer.close(parentData.zindex); // 关闭指定的弹窗
            }
        })

    })
</script>